package com.itheima.charstream1;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class CharStreamDemo12 {
    public static void main(String[] args) throws IOException {
        // 读取
        BufferedReader br = new BufferedReader(new FileReader("CharStream\\sort.txt"));
        List<Integer> numbers = new ArrayList<>();
        String line;
        while ((line = br.readLine()) != null) {
            for (String s : line.split(" ")) {
                numbers.add(Integer.parseInt(s));
            }
        }
        br.close();
        // 排序
        numbers = numbers.stream().sorted().collect(Collectors.toList());
        // 写入
        BufferedWriter bw = new BufferedWriter(new FileWriter("CharStream\\sort.txt", true));
        bw.newLine();
        for (Integer number : numbers) {
            bw.write(number + " ");
        }
        bw.flush();
        bw.close();
    }
}
